package net.sf.brutil.v0.light;

public class ErrorUtil {

	public static RuntimeException propagateError(String message,Throwable e){
		
		if (e instanceof RuntimeException)
			return (RuntimeException)e;
		else
			return new RuntimeException(message,e);
	}

	public static RuntimeException propagateError(Throwable e){
		return propagateError(e.getMessage(),e);
	}

	
	public static <E> void assertEmpty(E o1){
		assertEquals(true, ObjectUtil.isObjectEmpty(o1)," not empty:"+o1);
	}
	public static <E> void assertEquals(E o1,E o2){
		assertEquals(o1, o2,"");
	}
	public static <E> void assertEquals(E o1,E o2,String failureMessage){
		if (!ObjectUtil.equals(o1, o2)) throw new RuntimeException("assertion failed. msg:"+failureMessage+ "\no1:\n"+o1+"\no2:\n"+o2);
	}

	
	public static  void assertEquals(Double o1,Double o2,Double delta,String failureMessage){
		if (o1==null && o2==null) return;
		if (o1==null || o2==null) throw new RuntimeException("assertion failed. msg:"+failureMessage+ " o1:"+o1+" o2:"+o2);		
		if (Math.abs(o1-o2)>delta) throw new RuntimeException("assertion failed. msg:"+failureMessage+ " o1:"+o1+" o2:"+o2);
	}
	

}
